package org.example.SolutionNew001;

import java.util.*;

public class Hash01 {
    public static void main(String[] args) {
        Hash01 h = new Hash01();
        int[] nums=new int[]{3,2,4};
        System.out.println(Arrays.toString(h.twoSum(nums,6)));
    }

    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();
        int[] res=new int[2];
        for(int i=0;i<nums.length;i++){
            if(map.containsKey(target-nums[i])){
                res[0]=i;res[1]=map.get(target-nums[i]);
                return res;
            }else{
                map.put(nums[i],i);
            }
        }
        return res;
    }
}
